package com.cn.pet.service.impl;

import com.cn.pet.model.pojo.Brand;
import com.cn.pet.mapper.BrandMapper;
import com.cn.pet.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService{

    @Autowired
    BrandMapper brandMapper;

    @Override
    public List<Brand> findAllBrands() {
        return brandMapper.queryAll();
    }

    @Override
    public String addOrUpdateBrand(Brand brand) {
        String msg = null;
        if(brand.getId() == null) {
            try{
                brandMapper.insert(brand);
                msg = "新增品牌成功！";
            } catch (Exception e) {
                e.printStackTrace();
                msg = "新增品牌失败，请联系管理员！";
            }
        }
        else {
            try{
                brandMapper.update(brand);
                msg = "修改品牌成功！";
            } catch (Exception e) {
                e.printStackTrace();
                msg = "修改品牌失败，请联系管理员！";
            }
        }
        return msg;
    }

    @Override
    public String delBrand(Integer id) {
        String msg = null;
        try{
            brandMapper.delete(id);
            msg = "删除品牌成功！";
        } catch (Exception e) {
            e.printStackTrace();
            msg = "删除品牌失败，请联系管理员！";
        }
        return msg;
    }

}
